package cn.tonyandmoney.voicenotes.notes.filters;

import android.util.Log;

import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import cn.tonyandmoney.baidu.asr.entity.NluResult;
import cn.tonyandmoney.voicenotes.notes.enums.OperationEnum;
import cn.tonyandmoney.voicenotes.notes.presenter.IOperation;
import cn.tonyandmoney.voicenotes.utils.GsonUtils;

public class SearchFilter extends BaseFilter {

    private String TAG = "SearchFilter";

    public SearchFilter(IOperation iOperation) {
        super(iOperation);
    }

    @Override
    protected String getDomain() {
        return "intent";
    }

    @Override
    protected void operation(NluResult result) {
        Type listType = new TypeToken<LinkedList<SearchResult>>() {}.getType();
        List<SearchResult> results = GsonUtils.fromJson(result.getResults(),listType);
        if (results.isEmpty()) return;
        Log.i(TAG, "operation->%s" + results.get(0));
        Map<String, String> resMap = results.get(0).object;
        iOperation.operation(OperationEnum.FIND_SOMETHING, resMap);
    }


    static class SearchResult {
        private String domain;
        private String intent;
        private Map<String, String> object;

        public void setDomain(String domain) {
            this.domain = domain;
        }

        public SearchResult() {
            super();
        }

        public String getDomain() {
            return domain;
        }

        public String getIntent() {
            return intent;
        }

        public void setIntent(String intent) {
            this.intent = intent;
        }

        public Map<String, String> getObject() {
            return object;
        }

        public void setObject(Map<String, String> object) {
            this.object = object;
        }
    }
}
